﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VMuktiAPI;

namespace VMuktiGrid.Buddy
{
    /// <summary>
    /// Interaction logic for comboBox.xaml
    /// </summary>
    public partial class ctlPodBuddyList : UserControl
    {
        private int intBuddyCount = 0;

        public ctlPodBuddyList()
        {
            try
            {
                InitializeComponent();
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "ctlPodBuddyList()--:--ctlPodBuddyList.xaml.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }

        private void btnMenu_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                menuPopUP.IsOpen = (!menuPopUP.IsOpen);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "btnMenu_Click()--:--ctlPodBuddyList.xaml.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }

        private void btnClosePopUp_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                menuPopUP.IsOpen = (!menuPopUP.IsOpen);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "btnClosePopUp_Click()--:--ctlPodBuddyList.xaml.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }

        public bool AddBuddy(string strBuddyName)
        {
            try
            {
                int i = 0, tempBuddyCount=0;
                for (i = 0; i < stPanel.Children.Count; i++)
                {
                    if (stPanel.Children[i].GetType() == typeof(ctlBuddy) )
                    {
                        if (((ctlBuddy)stPanel.Children[i]).Title == strBuddyName)
                        {
                            break;
                        }
                        tempBuddyCount++;
                    }
                }
                if (tempBuddyCount == intBuddyCount)
                {
                    ctlBuddy objBuddy = new ctlBuddy();
                    objBuddy.Title = strBuddyName;
                    stPanel.Children.Add(objBuddy);
                    intBuddyCount++;
                    return true;
                }
                return false;
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "AddBuddy()--:--ctlPodBuddyList.xaml.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                return false;
            }
        }
    }
}
